package com.one.controller;

import com.one.bean.Cart;
import com.one.bean.Product;
import com.one.service.OrderFlashSaleService;
import com.one.util.RequestReturn;
import com.one.vo.ProductParamVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Create on 2022-01-20
 * <p>
 * Author: LiangWei
 * <p>
 * Description: 购物车业务web层
 **/
@Api(tags = "J.购物车操作")
@RestController
public class BuyCartController {
    @Autowired
    private OrderFlashSaleService orderFlashSaleService;

    /**
     *  添加购物车业务
     */
    @ApiOperation(value = "添加商品到购物车")
    @PostMapping("/AddProductToCart")
    RequestReturn<Product> AddProductToCart(@RequestBody ProductParamVo productParamVo){
        return orderFlashSaleService.addProductToCart(productParamVo);
    }


    /**
     *  删除单个购物车业务
     */
    @ApiOperation(value = "从购物车中删除单个商品")
    @DeleteMapping("/DeleteCart")
    @ApiImplicitParam(name = "cartId", required = true, value = "购物车id")
    RequestReturn<String> DeleteCart(@RequestParam Integer cartId){
        return orderFlashSaleService.deleteCart(cartId);
    }

    /**
     *  批量删除购物车业务
     */
    @ApiOperation(value = "从购物车中批量删除商品")
    @DeleteMapping("/DeleteManyCarts")
//    @ApiImplicitParam(name = "cartIdList", required = true, value = "购物车id集合")
    RequestReturn<String> DeleteManyCarts(@RequestParam List<Integer> cartIdList){
        return orderFlashSaleService.deleteManyCarts(cartIdList);
    }

    /**
     *  查询用户全部购物车业务
     */
    @ApiOperation(value = "查询用户购物车里的全部商品")
    @GetMapping("/findCartsByUserId")
    RequestReturn<List<Cart>> findCartsByUserId(){
        return orderFlashSaleService.selectCartsByUserId();
    }

    /**
     *  根据用户id删除所有的购物车
     */
    @DeleteMapping("/deAllCartsByUserId")
    @ApiOperation(value = "清空购物车")
    RequestReturn<String> deAllCartsByUserId(){
        return orderFlashSaleService.deleteAllCartsByUserId();
    }

    /**
     *  更新购物车商品数量信息
     */
    @PostMapping("/upProductNum")
    @ApiOperation(value = "更新购物车里的商品数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "productNum", required = true, value = "商品数量"),
            @ApiImplicitParam(name = "cartId", required = true, value = "地址id"),
    })
    RequestReturn<Cart> upProductNum(@RequestParam Integer productNum,@RequestParam Integer cartId){
        return orderFlashSaleService.updateProductNum(productNum,cartId);
    }

//    /**
//     *  将购物车的商品添加到收藏
//     */
//    @ApiOperation(value = "购物车添加收藏")
//    @PostMapping("/addCollect")
//    @ApiImplicitParam(name = "productId", required = true, value = "商品id")
//    RequestReturn<String> addCollect(@RequestParam Integer productId){
//        return orderFlashSaleService.addToCollect(productId);
//    }
}
